package com.fiberhome.student;

import java.util.List;

/**
 * 学生成绩计算器
 * 
 * @author jliu
 * 
 */
public class StudentCacl<T> {
	private Float avg=0.0f;
	private Integer max = Integer.MIN_VALUE;
	private Integer min = Integer.MAX_VALUE;

	public StudentCacl(List<T> ts, Gettor<T> gettor) {
		Integer current;
		
		for (int i = 0; i < ts.size(); i++) {
			current = gettor.getProperty(ts.get(i));
			
			if(current > max){
				max = current;
			}
			if(current < min){
				min = current;
			}
			
			avg += current;
		}
		
		avg = avg/ts.size();
	}

	public Float getAvg() {
		return avg;
	}

	public void setAvg(Float avg) {
		this.avg = avg;
	}

	public Integer getMax() {
		return max;
	}

	public void setMax(Integer max) {
		this.max = max;
	}

	public Integer getMin() {
		return min;
	}

	public void setMin(Integer min) {
		this.min = min;
	}
	
	
}

interface Gettor<T> {
	abstract Integer getProperty(T t);
}
